
{-# LANGUAGE DeriveDataTypeable, FlexibleContexts #-}


module ORel.Object where


import Data.Dynamic
import qualified Data.Map as Map

import ORel.ItemId
import ORel.SetProp
import ORel.Types



data Object typ
    = Object ItemId (Map.Map String Dynamic)
    deriving (Show, Typeable)


infixl 6 ...
(...) ::
    (Show prop, Typeable propTy
    ,PropAdd (prop,propTy) objTy objTy'
    ,PropType prop objTy' propTy
    ) 
    => Object objTy -> Set prop propTy -> Object objTy'
(Object id obj) ... (prop := val)
    = Object id $ Map.insert (show prop) (toDyn val) obj


getProp ::
    (Typeable propTy, Show prop
    ,PropType prop objTy propTy
    )
    => Object objTy -> prop -> propTy
getProp (Object id obj) prop
    = fromDyn val (error "unexpected dynamic type") -- FIXME: 
	where
		val = (Map.!) obj (show prop)



